#include "widget.h"
#include "ui_widget.h"
#include<QTimer>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    timer=new QTimer(this);

    //使⽤ connect 把 QTimer::timeout 信号和 Widget::updateTime 连接起来, 意味着每次触发 QTimer::timeout 都会执⾏ Widget::updateTime
    connect(timer,&QTimer::timeout,this,&Widget::updataTime);
    timer->start(1000);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::updataTime()
{
    int value=ui->lcdNumber->intValue();
    if(value<=0)
    {
        timer->stop();
        //1秒后自动关闭
        QTimer::singleShot(1000, this, [=](){
            this->close();
        });

        return;

    }
    ui->lcdNumber->display(value-1);
}
